package 迷宫问题;

import java.util.*;

public class Main {
    static int N = 1010, n;
    static int[][] g = new int[N][N];
    static PII[][] pre = new PII[N][N];
    static int[] dx = {-1, 1, 0, 0};
    static int[] dy = {0, 0, -1, 1};

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                g[i][j] = in.nextInt();
            }
        }
        PII end = new PII(n - 1, n - 1), start = new PII(0, 0);
        bfs(end);
        while (true) {
            int x = start.x, y = start.y;
            System.out.println(x + " " + y);
            if (x == n - 1 && y == n - 1) {
                break;
            }
            start = pre[x][y];
        }
    }

    private static void bfs(PII start) {
        Queue<PII> q = new LinkedList<>();
        q.offer(start);
        pre[start.x][start.y] = new PII(0, 0);
        while (!q.isEmpty()) {
            PII t = q.poll();
            for (int i = 0; i < 4; i++) {
                int a = dx[i] + t.x, b = dy[i] + t.y;
                if (a < 0 || a >= n || b < 0 || b >= n) {
                    continue;
                }
                if (pre[a][b] != null) {
                    continue;
                }
                if (g[a][b] == 1) {
                    continue;
                }
                pre[a][b] = t;
                q.offer(new PII(a, b));
            }
        }
    }
}

class PII {
    int x, y;

    public PII(int x, int y) {
        this.x = x;
        this.y = y;
    }
}